package dfs_bfs;

import java.util.*;

public class hu3_virs {
    static int zero = 0;
    static int s = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[][] num = new int[n][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                num[i][j] = sc.nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(num[i][j] == 0)
                    zero++;
            }
        }
        if(zero != 0)
            bfs(num);
        System.out.println(s);
    }
    public static void bfs(int[][] num){
        s++;
        Queue<int[]> queue = new LinkedList<>();
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < num.length; j++) {
                if(num[i][j] == 1){
                    queue.add(new int[]{i, j});
                }
            }
        }
        while(!queue.isEmpty()){
            int[] temp = queue.poll();
            int i = temp[0], j = temp[1];
            if(i - 1 >= 0 && num[i - 1][j] == 0){
                num[i - 1][j] = 1;
                zero--;
            }
            if(i + 1 < num.length && num[i + 1][j] == 0){
                num[i + 1][j] = 1;
                zero--;
            }
            if(j - 1 >= 0 && num[i][j - 1] == 0){
                num[i][j - 1] = 1;
                zero--;
            }
            if(j + 1 < num.length && num[i][j + 1] == 0){
                num[i][j + 1] = 1;
                zero--;
            }
        }
        if(zero != 0){
            bfs(num);
        }
    }
}
/*
3
1 0 1
0 0 0
1 0 1

4
1 0 0 0
0 0 0 0
0 0 0 0
0 1 0 0
 */